package com.yunji.framework_template.books.orm.persistence.model;

import com.yunji.framework_template.common.util.StringUtil;

public class BooksChapters {

    private Integer id;

    private Integer bookId;

    private Integer chapterIndex;

    private String  name;

    private Integer readTimes;

    private Integer likeTimes;

    private Integer commentTimes;

    private String  content;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getBookId() {
        return bookId;
    }

    public void setBookId(Integer bookId) {
        this.bookId = bookId;
    }

    public Integer getChapterIndex() {
        return chapterIndex;
    }

    public void setChapterIndex(Integer chapterIndex) {
        this.chapterIndex = chapterIndex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getReadTimes() {
        return readTimes;
    }

    public void setReadTimes(Integer readTimes) {
        this.readTimes = readTimes;
    }

    public Integer getLikeTimes() {
        return likeTimes;
    }

    public void setLikeTimes(Integer likeTimes) {
        this.likeTimes = likeTimes;
    }

    public Integer getCommentTimes() {
        return commentTimes;
    }

    public void setCommentTimes(Integer commentTimes) {
        this.commentTimes = commentTimes;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    // 如果内容的长度超过了1024,则展示部分内容
    public String getLessContent() {
        if (StringUtil.isEmpty(content)) {
            return null;
        }
        String noHtmlTagContent = this.content.replace("</p>", "_BRTAGE_");
        noHtmlTagContent = StringUtil.removeHtmlTags(noHtmlTagContent);
        noHtmlTagContent = noHtmlTagContent.replaceAll("_BRTAGE_", "<br>");

        if (noHtmlTagContent.length() <= 1024) {
            return noHtmlTagContent;
        } else {
            return noHtmlTagContent.substring(0, 1023);
        }
    }

}
